<!--应聘简历-->
<template>
  <div class="rightBodyContent">
    <div class="rightBodyContent-in">
      <div class="hearder-search">
        <div class="breadcrumb-container">
          <el-button type="primary" size="small" @click="addDevice(0)">新增班级轮播</el-button>
          <el-button size="small" @click="searchFn()"><i class="el-icon-refresh"></i>重置刷新</el-button>
          <span class="ml-10">每个班级只能添加一组轮播图</span>
        </div>
      </div>
      <!--本体列表，数据 -->
      <div class="table-body">
        <div class="table-body-box">
          <el-table
              ref="multipleTable"
              :data="arryList"
              :border="tableoption.tableBorder"
              tooltip-effect="dark">
            <el-table-column
                label="班级"
                align="center">
              <template slot-scope="scope">
                {{ scope.row.classes ? scope.row.classes.class_name : '--' }}
              </template>
            </el-table-column>
            <el-table-column
                label="轮播数"
                align="center"
                prop="picNumber">
            </el-table-column>
            <el-table-column
                align="center"
                label="操作"
                width="220">
              <template slot-scope="scope">
                <el-button size="small" @click="addDevice(scope.row.id)">查看/编辑详情</el-button>
                <el-button type="danger" size="small" @click="detelFn(scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <!--工具条 分页-->
      <el-col :span="24" class="toolbar">
        <el-pagination
            background
            :page-size="page.pagesize"
            :current-page="page.pageindex"
            layout="total, prev, pager, next"
            :total="page.total"
            @current-change="handleSizeChange"></el-pagination>
      </el-col>
    </div>
    <editDetail :visible.sync="editVisible" :imgId="imgId" @InitFn="InitFn"></editDetail>
  </div>
</template>

<script>
import {pagination, tableoption} from '@/utils/util.js'
import editDetail from "./editDetail";

export default {
  components: {
    editDetail
  },
  data() {
    return {
      editVisible: false,
      imgId: 0,
      tableoption: tableoption,
      page: {
        pageindex: pagination.pageIndex,
        pagesize: pagination.pageSize,
        total: pagination.total
      },
      arryList: [], // 数据列表
      searchForm: {
        student_name: ''
      },
    }
  },
  created() {
    this.InitFn()
  },
  methods: {
    // 初始化
    async InitFn() {
      let option = {
        p: this.page.pageindex,
      };
      let data = await this.$fetch(this.api.classActive.class_pic.index, option);
      for(let item of data.list.data){
        let picNumber = item.pic.split(',');
        item.picNumber = picNumber.length
      }
      this.arryList = data.list.data
      this.page.total = data.list.total
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
    addDevice(option) {
      this.imgId = option;
      this.editVisible = true;
    },
    searchFn() {
      this.page.pageindex = 1
      this.InitFn()
    },
    // 分页
    handleSizeChange(val) {
      this.page.pageindex = val
      this.InitFn()
    },
    detelFn(option) {
      let self_ = this;
      this.$confirm('此接送人将永久删除，确认删除此信息？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        self_.$post(this.api.classActive.pick_up.delete, {
          id: option.id
        }).then((response) => {
          if (response.code === 0) {
            this.InitFn()
            this.$message.success(response.msg)
          } else {
            this.$message.error(response.msg)
          }
        }).catch((err) => {
          console.log(err)
        })
      }).catch(() => {

      })
    }
  },
  mounted() {
  }
}
</script>
